﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Super.Common;
using Super.Entities;
using Super.Infrastructure;

namespace Super.DomainService
{
  public  class StockChangeTypeService:BaseService<StockChangeType>
  {
      private readonly DbContextAdapter _adp;
      private readonly BaseService<StockChangeType> _stockChangeTypeService;
      public StockChangeTypeService(DbContextAdapter adp) : base(adp)
      {
          _adp=adp;
          _stockChangeTypeService=new BaseService<StockChangeType>(adp);
      }

      public StockChangeType GetStockChangeModel(string Name, StockChangeTypeEnum InOut )
      {
          var io = (int) InOut;
          var model = _stockChangeTypeService.Repository.Find(a => a.Name.Contains(Name) && a.InOut==io).FirstOrDefault();
          if(model==null)
          {
              model=new StockChangeType();
              model.Name = Name;
              model.InOut = io;
              _stockChangeTypeService.Repository.InsertOrUpdate(model);
              _adp.SaveChanges();
          }
          return model;
      }
    }
}
